﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Drawing;
using Google.KML;
namespace MSAProject.AltitudeColor
{
    class ColorStyle
    {
        public string StyleName{get;set;}
        public Color StyleColor{get;set;}
        public geStyle Style { get; set; }

        public ColorStyle() {}

        public ColorStyle(Color styleColor)
        {
            StyleColor = styleColor;
            StyleName = getStyleId();
            prepareKMLStyle();
        }

        public override int GetHashCode() {
            return StyleColor.R + StyleColor.G * 2 + StyleColor.B * 3;
        } 

        public override bool Equals(Object obj){
            if(obj != null && obj is ColorStyle){
                ColorStyle colorStyle = (ColorStyle)obj;
                if (colorStyle.StyleName.Equals(StyleName)) {
                    return true;
                }
            }
            return false;
        }

        /// <summary>
        /// Method prepares KML style.
        /// </summary>
        private void prepareKMLStyle() {
            Style = new geStyle(StyleName);
            Style.PolyStyle = new gePolyStyle();
            Style.PolyStyle.Color.SysColor = StyleColor;
            Style.PolyStyle.ColorMode = geColorModeEnum.normal;
            Style.PolyStyle.Fill = true;
        }

        /// <summary>
        /// Method prepares name of style. Name is made by adding all red, green, blue value to one string.
        /// </summary>
        /// <returns>style name </returns>
        private string getStyleId() {
            return StyleColor.R.ToString() + StyleColor.G.ToString() + StyleColor.B.ToString();
        }
    }
}
